package com.fosu.dao;

import com.fosu.domain.Label;
import com.fosu.domain.ProductAndCampus;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zqa
 * @version 1.0
 * @date 2020/10/20 9:46
 */

@Mapper
@Repository
public interface LabelDao {


    /**查找所有标签
     * @return List<Label> 标签对象集合
     * @throws Exception
     */
    @Results(id="labelMap",value = {
            @Result(property = "productId", column = "product_id"),
            @Result(property = "isNew", column = "is_new"),
            @Result( property = "isNegotiable", column = "is_negotiable")
    })
    @Select("select * from  label")
  List<Label> findAll() throws  Exception;

    /**根据商品id查找标签
     * 根据首页用户传入的商品id获得特定标签
     * @param productId 商品id
     * @return Label 商品拥有的标签
     */
    @Select("select * " +
            "from label " +
            "where product_id = #{productId} "
    )
    @ResultMap(value = "labelMap")
   Label findLabelById(int productId);

    /**
     * 插入商品和可刀全新标签的关系
     * @param productId 商品id
     * @param isNew 标签：是否全新
     * @param isNegotiable 标签：是否可议价
     */
   @ResultMap(value ="labelMap")
    @Insert("insert into label(product_id,is_new,is_negotiable) values(#{productId},#{isNew},#{isNegotiable})")
    void save(
            @Param("productId") int productId
           ,@Param("isNew")int isNew
           ,@Param("isNegotiable")int isNegotiable);

    /**
     * 删除商品和可刀全新标签的关系
     * @param productId 商品id
     */
    @Delete("delete from label where product_id=#{productId}")
    void clean(int productId);
}
